/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.muni.fi.veles.marker;

import cz.muni.fi.veles.MapServer;
import cz.muni.fi.veles.maps.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.component.behavior.ClientBehaviorHolder;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;

/**
 * Abstract Marker component
 * @author Jan Ferko
 */
@JsfComponent(family=AbstractMarker.COMPONENT_FAMILY,
    type=AbstractMarker.COMPONENT_TYPE,
    renderer=@JsfRenderer(family=AbstractMarker.COMPONENT_FAMILY, type="cz.muni.fi.veles.MarkerRenderer")
)
public abstract class AbstractMarker extends UIComponentBase implements ClientBehaviorHolder{

    public static final String COMPONENT_FAMILY = "cz.muni.fi.veles";
    public static final String COMPONENT_TYPE = "cz.muni.fi.veles.Marker";  

    /**
     * Required attribute
     * @return latitude of marker
     */
    @Attribute(required=true)
    public abstract Double getLatitude();

    /**
     * Required attribute
     * @return longitude of marker
     */
    @Attribute(required=true)
    public abstract Double getLongitude();

    /**
     * Default value : true
     * @return indicator if marker is clickable
     */
    @Attribute(defaultValue="true")
    public abstract boolean isClickable();

    /**
     * Default value: false
     * @return indicator if marker is draggable
     */
    @Attribute(defaultValue="false")
    public abstract boolean isDraggable();

    /**
     * 
     * @return title of marker
     */
    @Attribute(defaultValue="")
    public abstract String getTitle();

    /**
     * 
     * @return path to custom marker image
     */
    @Attribute
    public abstract String getImage();
            
    /**
     * Resolves parent map server
     * @return parent map server
     */
    public MapServer resolveMapServer(){
        return this.getParentMap().getMapServer();
    }

    /**
     * 
     * @return parent map
     */
    public AbstractMap getParentMap(){
        UIComponent parent = this.getParent();
        while(parent != null && !(parent instanceof AbstractMap)){
            parent = parent.getParent();
        }
        AbstractMap map = (AbstractMap) parent;
        return map;
    }

//    @Override
//    public Collection<String> getEventNames() {
//        return Arrays.asList("mouseout");
//    }
//
//    @Override
//    public String getDefaultEventName() {
//        return "mouseout";
//    }
    
}
